package cn.edu.sig.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import cn.edu.sig.bean.User;
import cn.edu.sig.service.UserService;

@Controller
public class TestController {
	@Resource(name="userService")
	private UserService userService;

	@RequestMapping(value="addUser" ,method = RequestMethod.POST)
	public String add(
			@RequestParam(value="code", required = true)String code,
			@RequestParam(value="userName", required = true)String userName,
			@RequestParam(value="email", required = true)String email,
			@RequestParam(value="password", required = true)String password){
		
		User user = new User();
		user.setCode(code);
		user.setEmail(email);user.setUserName(userName);
		//user.setPassword(password);
		
		userService.add(user);
		
		return "redirect:list.html";
	}
	@RequestMapping(value="list" ,method = RequestMethod.GET)
	public String list(Model model){
		
		List<User> users = userService.findAll();
		
		model.addAttribute("users",users);
		
		return "userList";
	}
	@RequestMapping(value="add" ,method = RequestMethod.GET)
	public String addPage(){
		
		return "addUser";
	}
}
